package com.site.codegen;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.site.codegen.disposer.CommandDisposer;
import com.site.codegen.disposer.CommandDisposerFactory;
import com.site.codegen.vo.CommandArgs;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class CodegenApplication {

    public static void main(String[] args) {
        JSONObject json = new JSONObject();
        Arrays.stream(args).forEach(arg -> {
            int index = arg.indexOf("=");
            String key = arg.substring(0, index);
            String value = URLDecoder.decode(arg.substring(index + 1), StandardCharsets.UTF_8);
            json.put(key, value);
        });
        CommandArgs commandArgs = json.to(CommandArgs.class);
        CommandDisposerFactory factory = new CommandDisposerFactory();
        CommandDisposer commandDisposer = factory.getCommandDisposer(commandArgs.getFlag());
        Object result = commandDisposer.dispose(commandArgs.getContent());
        System.out.println(JSON.toJSONString(result));
    }
}
